package com.chaihu.front.service.common.impl;

import com.alibaba.fastjson.JSONObject;
import com.chaihu.core.base.service.front.AbstractComponentService;
import com.chaihu.core.context.IPageData;
import com.chaihu.front.service.common.CommonGetService;
import com.chaihu.utils.constant.ServiceConstant;
import com.chaihu.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * @ClassName CommonSMOImpl
 * @Description 通用服务处理
 **/
@Service("commonGetServiceImpl")
public class CommonGetServiceImpl extends AbstractComponentService implements CommonGetService {

    @Autowired
    private RestTemplate restTemplate;

    @Override
    protected void validate(IPageData pd, JSONObject paramIn) {

    }

    @Override
    protected ResponseEntity<String> doBusinessProcess(IPageData pd, JSONObject paramIn) throws Exception {
//        ComponentValidateResult result = super.validateStoreStaffCommunityRelationship(pd, restTemplate);
//        Map paramMap = BeanConvertUtil.beanCovertMap(result);
//        paramIn.putAll(paramMap);

        String apiUrl = ServiceConstant.SERVICE_API_URL + pd.getApiUrl() + mapToUrlParam(paramIn);

//        pd.setStoreId(result.getStoreId());
        ResponseEntity<String> responseEntity = this.callCenterService(restTemplate, pd, "",
                apiUrl,
                HttpMethod.GET);

        return responseEntity;
    }

    @Override
    public ResponseEntity<String> doService(IPageData pd) {
        return businessProcess(pd);
    }
}
